package com.ziyun.pop.modules.supp.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.service.goods.api.SellerEvaluateService;
import com.service.goods.api.SellerService;
import com.service.goods.api.SubSellerService;
import com.service.goods.constant.GoodsResult;
import com.service.goods.model.evaluate.SellerEvaluateResultDto;
import com.service.goods.model.seller.RegisterSellerParamDto;
import com.service.goods.model.seller.SellerInfoVO;
import com.service.ucenter.api.VerifyCodeService;
import com.utility.JsonUtils;
import com.utility.New;
import com.utility.StringUtils;
import com.ziyun.pop.common.e.DeleteEnum;
import com.ziyun.pop.common.utils.HttpClientUtil;
import com.ziyun.pop.common.utils.UserUtils;
import com.ziyun.pop.common.utils.VerificationCodeUtils;
import com.ziyun.pop.modules.goods.TwbVo.TwbStateCollectVo;
import com.ziyun.pop.modules.goods.service.GoodsService;
import com.ziyun.pop.modules.goods.vo.GoodsSalesVo;
import com.ziyun.pop.modules.order.service.OrderInfoService;
import com.ziyun.pop.modules.remittance.entity.RemittanceEntity;
import com.ziyun.pop.modules.remittance.service.RemittanceService;
import com.ziyun.pop.modules.storeMember.service.StoreMemberService;
import com.ziyun.pop.modules.storeMember.service.UserBaseInfoService;
import com.ziyun.pop.modules.supp.dao.ErpSellerInfoDao;
import com.ziyun.pop.modules.supp.dto.SellerCopyGoodsDto;
import com.ziyun.pop.modules.supp.dto.SellerInfoAuditDto;
import com.ziyun.pop.modules.supp.dto.SellerRegisterDto;
import com.ziyun.pop.modules.supp.entity.SellerInfoEntity;
import com.ziyun.pop.modules.supp.service.SellerInfoService;
import com.ziyun.pop.modules.supp.vo.*;
import io.renren.common.exception.RRException;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.common.utils.R;
import io.renren.modules.sys.entity.SysDeptEntity;
import io.renren.modules.sys.entity.SysUserEntity;
import io.renren.modules.sys.entity.SysUserRoleEntity;
import io.renren.modules.sys.service.SysDeptService;
import io.renren.modules.sys.service.SysUserRoleService;
import io.renren.modules.sys.service.SysUserService;
import io.renren.modules.sys.shiro.ShiroUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 商户入驻接口实现
 * @author gaosheng
 * @email
 * @date 2018-09-30 10:37
 */
@Slf4j
@Service("sellerInfoService")
public class SellerInfoServiceImpl extends ServiceImpl<ErpSellerInfoDao, SellerInfoEntity> implements SellerInfoService {

    @Value("${registerUserApi}")
    private String registerUserApi;
    @Autowired
    private SysUserService sysUserService;
    @Autowired
    private SysDeptService sysDeptService;
    @Autowired
    private SysUserRoleService sysUserRoleService;
    @Autowired
    private VerifyCodeService verifyCodeService;
    @Autowired
    private GoodsService goodsService;
    @Autowired
    private OrderInfoService orderInfoService;
    @Autowired
    private RemittanceService remittanceService;
    @Autowired
    private SubSellerService subSellerService;
    @Autowired
    private SellerEvaluateService sellerEvaluateService;
    @Autowired
    private StoreMemberService storeMemberService;
    @Autowired
    private UserBaseInfoService userBaseInfoService;
    @Autowired
    private SellerService sellerService;

    @Override
    public R saveSubSellerInfo(SellerRegisterDto sellerRegisterDto) {
        log.info("================= subseller register api start: " + UserUtils.getCurentUser().getUserId() + "," + UserUtils.getCurentUser().getUsername());
        Long sellerId = sellerRegisterDto.getSellerId();
        SellerInfoEntity sellerInfo = baseMapper.selectById(sellerId);
        SellerInfoVO sellerInfoVO = new SellerInfoVO();
        sellerInfoVO.setSellerMobile(sellerRegisterDto.getSellerMobile());
        sellerInfoVO.setVerifyCode(sellerRegisterDto.getVeriCode());
        sellerInfoVO.setSellerTel(sellerRegisterDto.getSellerTel());
        sellerInfoVO.setSellerQq(sellerRegisterDto.getSellerQq());
        sellerInfoVO.setSellerEmail(sellerRegisterDto.getSellerEmail());
        sellerInfoVO.setDoorheadName(sellerRegisterDto.getDoorheadName());
        sellerInfoVO.setSellerName(sellerRegisterDto.getSellerName());
        sellerInfoVO.setName(sellerRegisterDto.getName());
        sellerInfoVO.setAreaId(Integer.valueOf(sellerRegisterDto.getAreaId()));
        sellerInfoVO.setArea(sellerRegisterDto.getArea());
        sellerInfoVO.setAddr(sellerRegisterDto.getAddr());
        sellerInfoVO.setLogoUrl(sellerRegisterDto.getLogoUrl());
        sellerInfoVO.setBusinessUrl(sellerRegisterDto.getBusinessUrl());
        sellerInfoVO.setOperateType(sellerRegisterDto.getOperateType());
        sellerInfoVO.setMonthlyTradingScale(sellerRegisterDto.getMonthlyTradingScale());
        sellerInfoVO.setMainSellerId(sellerId);
        sellerInfoVO.setSellerType(sellerInfo.getSellerType());
        log.info("================= subseller register api param：" + JsonUtils.object2String(sellerInfoVO));
        GoodsResult<?> goodsResult = subSellerService.addsubMerchant(sellerInfoVO);
        log.info("================= subseller register api result：" + JsonUtils.object2String(goodsResult));
        int code = goodsResult.getCode();
        if (code != 1) {
            String message = goodsResult.getMessage();
            if (code == 999) {
                log.info("================= standard item find factory api error：" + message);
                throw new RRException("商户注册服务异常，请联系后台管理员");
            }
            return R.error(message);
        }
        return R.ok();
    }

    @Override
    public R queryPageSubSellerList(Map<String, Object> params) {
        Page<SellerInfoEntity> page = (Page<SellerInfoEntity>) this.page(
                new Query<SellerInfoEntity>(params).getPage(),
                new QueryWrapper<SellerInfoEntity>()
                        .eq("main_seller_id", params.get("sellerId"))
                        .eq("disabled", DeleteEnum.NOT_DELETE.toInt())
        );
        return R.ok().put("page", new PageUtils(page));
    }

    @Override
    public R checkVerifyCode(String sellerMobile, String verifyCode) {
        String checkVerifyCode = VerificationCodeUtils.checkVerifyCode(sellerMobile, verifyCode);
        return R.ok();
    }

    /**
     * 查询商户首页信息
     * @param sellerId
     * @return
     */
    @Override
    public SellerInfoVo querySellerInfo(Long sellerId) {
        return baseMapper.querySellerInfo(sellerId);
    }

    public void saveSmallProgramSeller(SellerInfoEntity sellerInfo, Long userId, Long mallUserId){
        // 更新会员信息
        Map<String, Object> userInfoMap = New.hashMap();
        userInfoMap.put("supplierId", sellerInfo.getSellerId());
        userBaseInfoService.updateByMap(userInfoMap, mallUserId);

        // 创建部门
        SysDeptEntity sysDept = new SysDeptEntity();
        sysDept.setParentId(0L);
        sysDept.setName(sellerInfo.getSellerName());
        sysDept.setSellerId(Long.valueOf(sellerInfo.getSellerId()));
        sysDeptService.save(sysDept);
        // 更新原有试用商户账号
        Map<String, Object> mallUserMap = New.hashMap();
        mallUserMap.put("sellerId", sellerInfo.getSellerId());
        mallUserMap.put("merchantType", sellerInfo.getSellerType());
        mallUserMap.put("username", sellerInfo.getSellerName());
        mallUserMap.put("email", sellerInfo.getSellerEmail());
        mallUserMap.put("mobile", sellerInfo.getSellerMobile());
        mallUserMap.put("status", 1);
        mallUserMap.put("deptId", sysDept.getDeptId());
        sysUserService.updateByMap(mallUserMap, userId);
        // 创建角色
        SysUserRoleEntity sysUserRole = new SysUserRoleEntity();
        sysUserRole.setUserId(userId);
        if (StringUtils.equals(sellerInfo.getSellerType(), "0")){
            sysUserRole.setRoleId(18L); // 供应商
        }else {
            sysUserRole.setRoleId(8L); // 工厂
        }
        sysUserRoleService.save(sysUserRole);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public R saveSellerInfo(SellerInfoAuditDto sellerInfoAuditDto) {
        log.info("===================seller register start========================");

        Long sellerId = sellerInfoAuditDto.getSellerId();
        SellerInfoEntity sellerInfo = this.getById(sellerId);
        if (sellerInfo == null){
            return R.error("未查询到商户信息");
        }
        String sellerOpenId = sellerInfo.getSellerOpenId();
        if (StringUtils.isNotBlank(sellerOpenId)){
            // 小程序使用商户绑定账号
            SysUserEntity sysUser = sysUserService.getOne(new QueryWrapper<>(new SysUserEntity()).eq("open_id", sellerOpenId));
            if (sysUser == null){
                return R.error("商户openid异常");
            }
            saveSmallProgramSeller(sellerInfo, sysUser.getUserId(), sysUser.getMallUserId());
        }else {
            // PC入驻商户审核
            SysUserEntity sysUser = sysUserService.getOne(new QueryWrapper<>(new SysUserEntity())
                    .eq("seller_id", sellerId)
                    .eq("status", 1)
            );
            if (sysUser == null || (sysUser != null && sysUser.getMallUserId() == null)){
                Map<String, String> params = new HashMap<>();
                params.put("sellerId", sellerId.toString());
                params.put("sellerName", sellerInfo.getSellerName());
                log.info("===================seller register api sellerId = {}, sellerName = {}", sellerId, sellerInfo.getSellerName());
                String result = HttpClientUtil.doPost(registerUserApi, params);
                log.info("===================seller register api result = {}", result);
                if (StringUtils.isBlank(result)){
                    return R.error("调用POP会员注册接口异常");
                }
                JSONObject resultJosn = (JSONObject) JSONObject.parse(result);
                String code = resultJosn.getString("code");
                if (!StringUtils.equals("200", code)){
                    return R.error(resultJosn.getString("msg"));
                }
                Long mallUserId = resultJosn.getLong("data");
                if (sysUser == null){
                    // 创建部门
                    SysDeptEntity sysDept = new SysDeptEntity();
                    sysDept.setParentId(0L);
                    sysDept.setName(sellerInfo.getSellerName());
                    sysDept.setSellerId(sellerId);
                    sysDeptService.save(sysDept);
                    // 创建用户
                    sysUser = new SysUserEntity();
                    sysUser.setDeptId(sysDept.getDeptId());
                    sysUser.setMallUserId(mallUserId);
                    sysUser.setSellerId(sellerId);
                    sysUser.setMerchantType(Integer.valueOf(sellerInfo.getSellerType()));
                    sysUser.setUsername(sellerInfo.getSellerName());
                    sysUser.setPassword("000000");
                    sysUser.setEmail(sellerInfo.getSellerEmail());
                    sysUser.setMobile(sellerInfo.getSellerMobile());
                    sysUser.setStatus(1);
                    sysUser.setCreateTime(new Date());
                    sysUserService.saveSysUser(sysUser);
                    // 创建角色
                    SysUserRoleEntity sysUserRole = new SysUserRoleEntity();
                    sysUserRole.setUserId(sysUser.getUserId());
                    if (StringUtils.equals(sellerInfo.getSellerType(), "0")){
                        sysUserRole.setRoleId(18L); // 供应商
                    }else {
                        sysUserRole.setRoleId(8L); // 工厂
                    }
                    sysUserRoleService.save(sysUserRole);
                }else {
                    // 若会员关系关联失败，继续关联
                    Map<String, Object> updateMap = new HashMap<>();
                    updateMap.put("mallUserId", mallUserId);
                    sysUserService.updateByMap(updateMap, sysUser.getUserId());
                }
            }
        }

        log.info("===================seller register end========================");

        return R.ok();
    }

    @Override
    public List<SalesVo> querySalesList(Long sellerId) {
        return baseMapper.querySalesList(sellerId);
    }

    @Override
    public CustomVo getCustom(Long sellerId) {
        return baseMapper.getCustom(sellerId);
    }

    @Override
    public SellerShipVo queryShipInfo(Long sellerId) {
        return baseMapper.queryShipInfo(sellerId);
    }

    @Override
    public R sellerCopyGoods(SellerCopyGoodsDto sellerCopyGoodsDto) {
        log.info("===================seller copyGoods start params：" + sellerCopyGoodsDto.toString());
        Long sellerId = sellerCopyGoodsDto.getSellerId();
        Long fromSellerId = sellerCopyGoodsDto.getFromSellerId();
        R r = goodsService.copyGoods(sellerId, fromSellerId);
        log.info("===================seller copyGoods result  = {}", r.toString());
        int code = (int) r.get("code");
        if (code != 0){
            String msg = (String) r.get("msg");
            return R.error(msg);
        }
        return R.ok();
    }

    @Override
    public void updateByMap(Map<String, Object> map, Long sellerId) {
        baseMapper.updateByMap(map, sellerId);
    }

    @Override
    public R getSellerInfo(Long sellerId) {
        SellerInfoApiVo sellerInfoApiVo =  baseMapper.getSellerInfo(sellerId);
        return R.apiOk(sellerInfoApiVo);
    }

    @Override
    public R getSellerData(Long sellerId) {
        // 销售统计
        SellerOrderApiVo sellerOrderApiVo = orderInfoService.getSellerOrder(sellerId);
        int onlineCount = storeMemberService.onlineCount(sellerId.intValue());
        int offlineCount = storeMemberService.offlineCount(sellerId.intValue());
        int totalCustomer = onlineCount + offlineCount;
        BigDecimal totalMoney = sellerOrderApiVo.getTotalMoney();
        BigDecimal tCustomer = new BigDecimal(totalCustomer);
        BigDecimal customerMoney = BigDecimal.ZERO;
        int compare = tCustomer.compareTo(BigDecimal.ZERO);
        if (compare > 0){
            customerMoney = totalMoney.divide(tCustomer, 2, BigDecimal.ROUND_HALF_UP);
        }
        sellerOrderApiVo.setCustomerMoney(customerMoney);
        sellerOrderApiVo.setTotalCustomer(totalCustomer);
        List<SalesVo> salesList = this.querySalesList(sellerId);
        sellerOrderApiVo.setSalesVos(salesList);

        // 商品统计
        TwbStateCollectVo twbGoodsStateCount = goodsService.getTwbGoodsStateCount(sellerId);
        List<GoodsSalesVo> goodsSalesVos = goodsService.getGoodsSalesList(sellerId);
        SellerGoodsApiVo goodsApiVo = new SellerGoodsApiVo();
        goodsApiVo.setTwbStateCollectVo(twbGoodsStateCount);
        goodsApiVo.setGoodsSalesVos(goodsSalesVos);

        // 客户管理
        SellerCustomerApiVo customerApiVo = new SellerCustomerApiVo();
        customerApiVo.setCustomerOnline(onlineCount);
        customerApiVo.setCustomerOffline(offlineCount);
        customerApiVo.setTotalCustomer(totalCustomer);

        int onlineNewCount = storeMemberService.onlineNewCount(sellerId.intValue());
        int offlineNewCount = storeMemberService.offlineNewCount(sellerId.intValue());
        int newCustom = onlineNewCount + offlineNewCount;
        int oldCustom = totalCustomer - newCustom;
        customerApiVo.setNewCustom(newCustom);
        customerApiVo.setOldCustom(oldCustom);

        int repeatBuy = storeMemberService.repeatBuy(sellerId.intValue());
        BigDecimal rePurchaseRate = BigDecimal.ZERO;
        if (compare > 0){
            rePurchaseRate = BigDecimal.valueOf(repeatBuy).divide(tCustomer, 4, BigDecimal.ROUND_HALF_UP);
        }
        String rate = rePurchaseRate.multiply(BigDecimal.valueOf(100)).stripTrailingZeros().toPlainString() + "%";
        customerApiVo.setRePurchaseRate(rate);
        ShopVo shopVo = new ShopVo();
        shopVo.setSellerOrderApiVo(sellerOrderApiVo);
        shopVo.setSellerGoodsApiVo(goodsApiVo);
        shopVo.setSellerCustomerApiVo(customerApiVo);

        // 客户评价
        try {
            log.info("===================seller evaluate api params：" + sellerId);
            GoodsResult<SellerEvaluateResultDto> sellerComprehensiveEvaluate = sellerEvaluateService.getSellerComprehensiveEvaluate(sellerId);
            log.info("===================seller evaluate api result：" + JsonUtils.object2String(sellerComprehensiveEvaluate));
            SellerEvaluateResultDto sellerEvaluateResultDto = sellerComprehensiveEvaluate.getData();
            SellerEvaluateApiVo sellerEvaluateApiVo = new SellerEvaluateApiVo();
            sellerEvaluateApiVo.setDisappointedNum(sellerEvaluateResultDto.getDisappointedNum());
            sellerEvaluateApiVo.setFavorableRate(sellerEvaluateResultDto.getFavorableRate());
            sellerEvaluateApiVo.setFavorNum(sellerEvaluateResultDto.getFavorNum());
            sellerEvaluateApiVo.setNormalNum(sellerEvaluateResultDto.getNormalNum());
            shopVo.setSellerEvaluateApiVo(sellerEvaluateApiVo);
        }catch (Exception e){
            log.error("===================seller evaluate api error：" + e.getMessage());
            e.printStackTrace();
        }

        return R.apiOk(shopVo);
    }

    @Override
    public R getSellerTodayData(Long sellerId) {
        SellerTodayApiVo sellerTodayApiVo = baseMapper.getSellerTodayData(sellerId);
        return R.apiOk(sellerTodayApiVo);
    }

    @Override
    public Integer getSelfByOrderNo(String orderNo) {
        return baseMapper.getSelfByOrderNo(orderNo);
    }

    @Override
    public R bindBankCard(String receiverName,String receiverCredential,String receiverAccount,String receiverAccountBranch,Long sellerId) {
        //判断该商户是否已经绑定银行卡
        RemittanceEntity entity = remittanceService.getOne(new QueryWrapper<RemittanceEntity>().eq("seller_id", sellerId));
        if (entity != null) {
            //已经绑定银行卡,就更新
            entity.setReceiverName(receiverName);
            entity.setReceiverCredential(receiverCredential);
            entity.setReceiverAccount(receiverAccount);
            entity.setReceiverAccountBranch(receiverAccountBranch);
            remittanceService.updateById(entity);
            return R.apiOk("银行卡更新成功!");
        }
        //没有绑定就新增
        SellerInfoEntity sellerInfoEntity = this.getById(sellerId);
        RemittanceEntity remittanceEntity = new RemittanceEntity();
        remittanceEntity.setSellerId(sellerId.intValue());
        remittanceEntity.setReceiverName(receiverName);
        remittanceEntity.setReceiverCredential(receiverCredential);
        remittanceEntity.setReceiverAccount(receiverAccount);
        remittanceEntity.setReceiverAccountBranch(receiverAccountBranch);
        remittanceEntity.setMerchantType(Integer.valueOf(sellerInfoEntity.getSellerType()));
        remittanceEntity.setCredentialType(1);
        remittanceEntity.setReceiverBankAccountPro("0");
        remittanceEntity.setCurrency("人民币");
        remittanceEntity.setPaymentType("快速");
        remittanceEntity.setBusinessType("普通汇兑");
        remittanceEntity.setExpectDay("20080808");
        remittanceEntity.setExpectTime("0800");
        remittanceEntity.setPaymentBranch("武汉雄楚金地城支行");
        boolean b = remittanceService.save(remittanceEntity);
        if (b) {
            return R.apiOk("银行卡设置成功!");
        }else {
            return R.apiError(500,"操作异常,请联系管理员!");
        }
    }

    @Override
    public R bankCard(Integer sellerId) {
        RemittanceEntity entity = remittanceService.getOne(new QueryWrapper<RemittanceEntity>().eq("seller_id",sellerId));
        if (entity != null) {
            BankCard bankCard = new BankCard();
            String account = entity.getReceiverAccount();
            StringBuilder sb = new StringBuilder(account);
            sb.replace(0, 7, "********");
            bankCard.setReceiverAccount(sb.toString());
            bankCard.setReceiverAccountBranch(entity.getReceiverAccountBranch());
            return R.apiOk(bankCard);
        }else {
            return R.apiOk("暂无数据,未设置银行卡!");
        }
    }

    @Override
    public synchronized R initSellerMallUserId(Integer nums) {
        log.info("=================== init sellerMallUserId start ===================");
        List<SellerInfoEntity> sellerInfoEntities = baseMapper.getSellerNoMallUserId(nums);
        for (SellerInfoEntity sellerInfo : sellerInfoEntities){
            Integer sellerId = sellerInfo.getSellerId();
            String sellerName = sellerInfo.getSellerName();
            Map<String, String> sellerMap = new HashMap<>();
            sellerMap.put("sellerId", sellerId.toString());
            sellerMap.put("sellerName", sellerName);
            try {
                log.info("=================== init sellerMallUserId param sellerId = {}, sellerName = {}", sellerId, sellerName);
                String result = HttpClientUtil.doPost(registerUserApi, sellerMap);
                log.info("=================== init sellerMallUserId result = {}", result);
                JSONObject resultJosn = (JSONObject) JSONObject.parse(result);
                String code = resultJosn.getString("code");
                if (!StringUtils.equals("200", code)){
                    String msg = resultJosn.getString("msg");
                    log.error("=================== init sellerMallUserId error = {}", msg);
                }else {
                    List<SysUserEntity> sysUserEntities = sysUserService.list(new QueryWrapper<>(new SysUserEntity())
                            .eq("seller_id", sellerId)
                    );
                    if (sysUserEntities.size() > 0){
                        Map<String, Object> userMap = new HashMap<>();
                        Long mallUserId = resultJosn.getLong("data");
                        userMap.put("mallUserId", mallUserId.toString());
                        List<Long> userIds = sysUserEntities.stream().map(SysUserEntity::getUserId).collect(Collectors.toList());
                        sysUserService.updateBatchByMap(userMap, userIds);
                        log.info("=================== init sellerMallUserId user = {}", sysUserEntities.size());
                    }
                }
            }catch (Exception e){
                e.printStackTrace();
                log.error("=================== init sellerMallUserId exception = {}", e.getMessage());
            }
        }
        log.info("=================== init sellerMallUserId end ===================");
        return R.ok();
    }

    @Override
    public SysUserEntity initUserWithOpenId(String openId, String uuid) {
        // 生成pop_sys_user with open id
        SysUserEntity sysUser = new SysUserEntity();
        //sysUser.setSellerId(1L);// todo 此处应该填写 模板商户
        sysUser.setMerchantType(0);
        sysUser.setUsername(openId);
        sysUser.setPassword(ShiroUtils.sha1("000000"));
        sysUser.setStatus(1);
        sysUser.setOpenId(openId);
        sysUser.setUuid(uuid);
        sysUser.setCreateTime(new Date());
        sysUser.setDelFlag(0);
        this.sysUserService.save(sysUser);
        // 生成 user_base_info
        Map<String, String> params = new HashMap<>();
        params.put("sellerId", "");
        params.put("sellerName", "");
        log.info("===================seller register api sellerId = {}, sellerName = {}", null, "演示供应商");
        String result = HttpClientUtil.doPost(registerUserApi, params);
        log.info("===================seller register api result = {}", result);
        if (StringUtils.isBlank(result)){
            throw new RRException("调用POP会员注册接口异常");
        }
        JSONObject resultJosn = (JSONObject) JSONObject.parse(result);
        String code = resultJosn.getString("code");
        if (!StringUtils.equals("200", code)){
            throw new RRException(resultJosn.getString("msg"));
        }
        Long mallUserId = resultJosn.getLong("data");
        //更新 pop_sys_user  mallUserId
        sysUser.setMallUserId(mallUserId);
        this.sysUserService.updateById(sysUser);
        return sysUser;
    }

    @Override
    public R registerSeller(RegisterSellerParamDto registerSellerParamDto) {
        log.info("================= seller register api param：" + JsonUtils.object2String(registerSellerParamDto));
        GoodsResult<?> goodsResult = sellerService.registerSeller(registerSellerParamDto);
        log.info("================= seller register api result：" + JsonUtils.object2String(goodsResult));
        int code = goodsResult.getCode();
        if (code != 1) {
            String message = goodsResult.getMessage();
            if (code == 999) {
                log.error("================= seller register api error：" + message);
                message = "商户注册服务异常";
            }
            return R.apiError(500, message);
        }
        return R.apiOk("商户注册成功");
    }

}
